<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        .psw {
            width: 430px;
            height: 50px;
            margin: 0 auto;
            margin-top: 10px;
            line-height: 50px;
        }
        
        .psw .tips {
            display: inline-block;
            visibility: hidden;
            color: #999;
            font-size: 12px;
            background: url(images/mess.png) no-repeat left center;
            padding-left: 20px;
        }
        
        .wrong {
            display: inline-block;
            color: red;
            font-size: 12px;
            background: url(images/wrong.png) no-repeat left center;
            padding-left: 20px;
        }
        
        .right {
            display: inline-block;
            color: green;
            font-size: 12px;
            background: url(images/right.png) no-repeat left center;
            padding-left: 20px;
        }
    </style>
</head>

<body>
    <div class="psw">
        <span style="color: red;">*</span>
        <span>设置密码：</span>
        <input type="password" id="">
        <p class="tips">
            6-16位字符,区分大小写</p>
    </div>
    <script>
        var psw = document.querySelector('input');
        var tips = document.querySelector('.tips');
        psw.onfocus = function() {
            tips.style.visibility = 'visible';

        }
        psw.onblur = function() {
            if (this.value.length != 0 && this.value.length < 6 || this.value.length > 16) {
                tips.className = 'wrong';
                tips.innerHTML = '密码长度错误';
                console.log('错误');
            } else if (this.value.length == 0) {
                tips.className = 'tips';
                tips.style.visibility = 'hidden';

            } else {
                tips.className = 'right';
                tips.innerHTML = '密码输入正确';
                console.log('错误');
            }
        }
    </script>



    <div class="psw">
        <span style="color: red;">*</span>
        <span>设置密码：</span>
        <input type="password" name="" id="">
        <p class="tips">
            6-16位字符,区分大小写</p>
    </div>

</body>

</html>